
*The purpose of this file is to replicate the analyses in Making Young Voters: The Impact of Preregistration on Young Voter Turnout
*These are organized by Tables.

**********************************  CPS MODELS ********************************** 

set mem 5G

cd "C:\projects\Data\Preregistration Paper\CPS Analysis" // switch to your working directory

*Table 1 
use "CPS data 2.5.14.dta", clear
sort year
by year: sum voted if state=="HI"
by year: sum voted if state=="FL"
by year: sum voted if state=="OR"
by year: sum voted if state=="CA"
by year: sum voted if state=="NC"
by year: sum voted if state=="RI"
by year: sum voted if state=="DC"
by year: sum voted if state=="DE"
by year: sum voted if state=="MD"
by year: sum voted if state=="ME"

gen non_pre_reg_state=0 if state=="HI" | state=="FL" | state=="OR" | state=="CA" | state=="NC" | state=="RI" | state=="DC" | state=="DE" | state=="MD" | state=="ME"
replace non_pre_reg_state=1 if non_pre_reg_state==.

by year: sum voted if non_pre_reg_state==0
by year: sum voted if non_pre_reg_state==1

*Table 2
use "CPS data 2.5.14.dta", clear
merge m:1 state year using "CPS state controls 3.24.14.dta" // brings in state-level controls

*FE (UB)
xi: reg voted pre_reg_state i.state*i.year age registered married female f_income college_degree metropolitan white time_at_address biz_farm_employ interview_in_person dmv_register hispanic_encode  if age<23, cluster(state_year)
*Lag (LB)
xi: reg voted pre_reg_state lag2_vote_18_22 age married female registered f_income college_degree metropolitan white hispanic_encode time_at_address biz_farm_employ interview_in_person dmv_register i.year if age<23, cluster(state_year)

*Mentioned in passing: If we're concered with including registration status variable, look only among the registered.
*Lag (LB)
xi: reg voted pre_reg_state lag2_vote_18_22 age married female f_income college_degree metropolitan white hispanic_encode time_at_address biz_farm_employ interview_in_person dmv_register i.year if age<23 & registered==1, cluster(state_year)
*FE (UB)
xi: reg voted pre_reg_state i.state*i.year age married female f_income college_degree metropolitan white time_at_address biz_farm_employ interview_in_person dmv_register hispanic_encode  if age<23 & registered==1, cluster(state_year)

*Table A1
use "CPS data 2.5.14.dta", clear
merge m:1 state year using "CPS state controls 3.24.14.dta" // brings in state-level controls

qui: eststo: xi: probit voted pre_reg_state lag2_vote_18_22 mean_voted_state age married female f_income registered college_degree metropolitan white hispanic_encode time_at_address biz_farm_employ interview_in_person dmv_register i.year if age<23, cluster(state_year)
margins, dydx(pre_reg_state) at((mean) lag2_vote_18_22 mean_voted_state age  f_income  time_at_address (median) married female college_degree metropolitan  white hispanic_encode biz_farm_employ interview_in_person dmv_register) 

qui: eststo: xi: probit voted pre_reg_state i.state*i.year age registered age married female f_income college_degree metropolitan white time_at_address biz_farm_employ interview_in_person dmv_register  if age<23, cluster(state_year) 
margins, dydx(pre_reg_state) at((mean) age  f_income  time_at_address (median) married female college_degree metropolitan  white  biz_farm_employ interview_in_person dmv_register) 
	
qui: eststo: xi: probit voted pre_reg_state lag2_vote_18_25 mean_voted_state age married female registered f_income college_degree metropolitan white hispanic_encode time_at_address biz_farm_employ interview_in_person dmv_register i.year if age<26, cluster(state_year)
margins, dydx(pre_reg_state) at((mean) lag2_vote_18_25 mean_voted_state age  f_income  time_at_address (median) married female college_degree metropolitan  white hispanic_encode biz_farm_employ interview_in_person dmv_register) 

qui: eststo: xi: probit voted pre_reg_state i.state*i.year age registered age married female f_income college_degree metropolitan white time_at_address biz_farm_employ interview_in_person dmv_register  if age<26, cluster(state_year) 
margins, dydx(pre_reg_state) at((mean) age  f_income  time_at_address (median) married female college_degree metropolitan  white  biz_farm_employ interview_in_person dmv_register) 


**********************************   FLORIDA Models in the paper   ******************************************************************************************************

*Treatment graph
cd "C:\projects\Data\Preregistration Paper\Analysis\" // insert working folder here.


use "Pre-Reg FL Data 8.6.13.dta", clear

gen days_from_20081=-days_from_2008

*Figure 1
twoway (sunflower prereg days_from_20081 , light(1000) dark(10000) ylabel(0(.2)1) xline(0, lpattern(shortdash) lcolor(gs10)) ///
	xtitle("Proximity to Ineligibility to Vote (birthdays)") ytitle("Predicted Probability of Preregistering") /// 
	msymbol(p) msize(small) legend(off) ///
	xlabel(-184 "5/4/90" -152 "6/4" -122 "7/4" -91 "8/4" ///
	-60 "9/4" -30 "10/4" 0 "11/4" 31 "12/4" 62 "1/4/91" ///
	93 "2/4" 121 "3/4" 152 "4/4" 184 "5/4", labsize(small)) ///
	ylabel(, labsize(small))) ///
	(lpoly prereg days_from_20081 if days_ratio_flipped>0, lcolor(black) lwidth(thick))	///
	(lpoly prereg days_from_20081 if days_ratio_flipped<=0, lcolor(black) lwidth(thick))


*First RD Results Table (and paper appendix table with controls)

*Table 3 & Table 5 (t5 is the same as t3, but with control coefficients reported)
eststo clear
use "Pre-Reg FL Data 8.6.13.dta", clear
eststo: reg voted_2012 non_eligible_2008 days_ratio_flipped voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1  if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
eststo: ivregress 2sls voted_2012 (prereg=non_eligible_2008 days_ratio_flipped) days_ratio_flipped voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1 if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
use "2004 and 2008.dta", clear // Data combining 2004 & 2008
eststo: xi: reg voted treatment_interaction non_eligible i.year voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender prop_poverty_county turnout_county age_county prop_white_county prop_black_county dem_office_county hs_degree days_ratio_flipped if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
use "Pre-Reg FL Data 8.6.13.dta", clear
eststo: ivregress 2sls voted_2012 (prereg=non_eligible_2008 days_ratio_flipped) days_ratio_flipped voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender   county_fe* if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
esttab, tex se(3)

*Table 4 & Table A3 (with controls)
eststo clear
eststo: regress voted_2012 non_eligible_2008 days_ratio_flipped voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1 if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
eststo: regress voted_2012 non_eligible_2008 days_ratio_flipped voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1 if days_ratio_flipped<.2 & days_ratio_flipped>-.2 & voted_2008==0, r
eststo: ivregress 2sls voted_2012 (prereg=non_eligible_2008 days_ratio_flipped) days_ratio_flipped voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1 if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
eststo: ivregress 2sls voted_2012 (prereg=non_eligible_2008 days_ratio_flipped) days_ratio_flipped voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1 if days_ratio_flipped<.2 & days_ratio_flipped>-.2 & voted_2008==0, r
esttab, tex se(3)

*Figure 2--plotted bandwidth
rd voted_2012 prereg days_ratio_flipped, mbw(10(10)150) bdep

*Figure 3--Stylized Visualization of TOT (1)
egen mean1=mean(voted_2012), by(days_ratio_flipped)
twoway (scatter mean1 days_ratio_flipped) (lpolyci voted_2012 days_ratio_flipped if days_ratio_flipped>0, yscale(range(.2 .6)) plotregion(margin(zero))) (lpolyci voted_2012 days_ratio_flipped if days_ratio_flipped<0, yscale(range(.2 .6)) plotregion(margin(zero))) 

******************* Online Appendix

*Table A1
eststo clear
use "Pre-Reg FL Data 8.6.13.dta", clear
eststo: probit voted_2012 non_eligible_2008 days_ratio_flipped voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1  if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
margins, pred(pr) at( non_eligible_2008=(0(1)1) (median) non_eligible_2008 voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender obamaofficeincounty0or1 (mean) days_ratio_flipped hs_degree poverty turnout age white black) 
eststo: ivprobit voted_2012 (prereg=non_eligible_2008 days_ratio_flipped) days_ratio_flipped voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1 if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
margins, pred(pr) at( prereg=(0(1)1) (median) non_eligible_2008 voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender obamaofficeincounty0or1 (mean) days_ratio_flipped hs_degree poverty turnout age white black) 
use "2004 and 2008.dta", clear
gen two=1 if year==2008
replace two=0 if year==2004
eststo: probit voted treatment_interaction non_eligible two voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender prop_poverty_county turnout_county age_county prop_white_county prop_black_county dem_office_county hs_degree days_ratio_flipped if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
margins, pred(pr) at( treatment_interaction=(0(1)1) (median) non_eligible two voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender dem_office_county (mean) prop_poverty_county turnout_county age_county prop_white_county prop_black_county hs_degree days_ratio_flipped) 
use "Pre-Reg FL Data 8.6.13.dta", clear
eststo: ivprobit voted_2012 (prereg=non_eligible_2008 days_ratio_flipped) days_ratio_flipped voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender county_fe* if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r mle
margins, pred(pr) at(prereg=(0(1)1) (median) voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  (mean) days_ratio_flipped) 

*Table A2
use "Pre-Reg FL Data 8.6.13.dta", clear
ttest prereg if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)
ttest voter_is_black if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)
ttest voter_is_white if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)
ttest voter_is_hispanic  if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)
ttest voter_is_minorrace if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)
ttest voter_is_democrat if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)
ttest voter_is_female if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)
ttest hs_degree if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)
ttest pctpoverty2008 if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008) 
ttest medianhouseholdincome2008 if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008) 
ttest population_2008 if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)
ttest medianagefrom20072011acs if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)
ttest whitenonhispanic if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)
ttest blacknonhispanic if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)
ttest hispanicanyrace if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)
ttest numberofcongregations if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)
ttest obamaofficeincounty0or1 if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)
ttest householdsthataremarriedcouplesa if days_from_2008<18 & days_from_2008>-18, by(non_eligible_2008)

*Figure A1 is in R

*Table A4
use "Pre-Reg FL Data 8.6.13.dta", clear
eststo clear
eststo: probit voted_2012 non_eligible_2008 days_ratio_flipped voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1  if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
margins, pred(pr) at( non_eligible_2008=(0(1)1) (median) non_eligible_2008 voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender obamaofficeincounty0or1 (mean) days_ratio_flipped hs_degree poverty turnout age white black) 
eststo: ivprobit voted_2012 (prereg=non_eligible_2008 days_ratio_flipped) days_ratio_flipped voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1 if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
margins, pred(pr) at( prereg=(0(1)1) (median) non_eligible_2008 voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender obamaofficeincounty0or1 (mean) days_ratio_flipped hs_degree poverty turnout age white black) 
use "2004 and 2008.dta", clear
gen two=1 if year==2008
replace two=0 if year==2004
eststo: probit voted treatment_interaction non_eligible two voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender prop_poverty_county turnout_county age_county prop_white_county prop_black_county dem_office_county hs_degree days_ratio_flipped if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
margins, pred(pr) at( treatment_interaction=(0(1)1) (median) non_eligible two voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender dem_office_county (mean) prop_poverty_county turnout_county age_county prop_white_county prop_black_county hs_degree days_ratio_flipped) 
use "Pre-Reg FL Data 8.6.13.dta", clear
eststo: ivprobit voted_2012 (prereg=non_eligible_2008 days_ratio_flipped) days_ratio_flipped voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender county_fe* if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r mle
margins, pred(pr) at(prereg=(0(1)1) (median) voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  (mean) days_ratio_flipped) 

*Table A5
use "C:\projects\Data\Preregistration Paper\Analysis\Pre-Reg FL Data 8.6.13.dta", clear
eststo clear
eststo: reg voted_2012 non_eligible_2008 days_ratio_flipped  if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
eststo: ivregress 2sls voted_2012 (prereg=non_eligible_2008 days_ratio_flipped) days_ratio_flipped  if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
use "C:\projects\Data\Preregistration Paper\Analysis\2004 and 2008.dta", clear
eststo: xi: reg voted treatment_interaction non_eligible i.year  if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
use "C:\projects\Data\Preregistration Paper\Analysis\Pre-Reg FL Data 8.6.13.dta", clear
eststo: ivregress 2sls voted_2012 (prereg=non_eligible_2008 days_ratio_flipped) days_ratio_flipped   county_fe* if days_ratio_flipped<.2 & days_ratio_flipped>-.2, r
esttab, tex se(3)

*Table A6
use "C:\projects\Data\Preregistration Paper\Analysis\Pre-Reg FL Data 8.6.13.dta", clear
rd voted_2012 prereg days_ratio_flipped, r
rd voted_2012 prereg days_ratio_flipped, covar(voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1) r
 
*Table A7
eststo: ivregress 2sls voted_2012 (prereg=non_eligible_2008 days_ratio_flipped) days_ratio_flipped voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1, r
eststo: ivregress 2sls voted_2012 (prereg=non_eligible_2008 days_ratio_flipped days_ratio_flipped_2) days_ratio_flipped days_ratio_flipped_2 voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1, r
eststo: ivregress 2sls voted_2012 (prereg=non_eligible_2008 days_ratio_flipped days_ratio_flipped_2 days_ratio_flipped_3) days_ratio_flipped days_ratio_flipped_2 days_ratio_flipped_3  voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1, r
eststo: ivregress 2sls voted_2012 (prereg=non_eligible_2008 days_ratio_flipped days_ratio_flipped_2 days_ratio_flipped_3 days_ratio_flipped_4) days_ratio_flipped days_ratio_flipped_2 days_ratio_flipped_3 days_ratio_flipped_4 voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1, r
eststo: ivregress 2sls voted_2012 (prereg=non_eligible_2008 days_ratio_flipped days_ratio_flipped_2 days_ratio_flipped_3 days_ratio_flipped_4 days_ratio_flipped_5) days_ratio_flipped days_ratio_flipped_2 days_ratio_flipped_3 days_ratio_flipped_4 days_ratio_flipped_5 voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1, r


**** A IN THE PAPER

*PARTY HETEROGENEITIES
rd voted_2012 prereg days_ratio_flipped if voter_is_republican==1, covar(voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace  voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1) r
rd voted_2012 prereg days_ratio_flipped if voter_is_democrat==1, covar(voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace    voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1) r

*RACE
rd voted_2012 prereg days_ratio_flipped if voter_is_white==1 , covar(voter_is_democrat voter_is_minorparty voter_is_unaffiliated   voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1) r
rd voted_2012 prereg days_ratio_flipped if voter_is_white==0, covar(voter_is_democrat voter_is_minorparty voter_is_unaffiliated    voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1) r

*GENDER
rd voted_2012 prereg days_ratio_flipped if voter_is_female==1  , covar(voter_is_democrat voter_is_minorparty voter_is_unaffiliated   voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace  hs_degree poverty turnout age white black obamaofficeincounty0or1) r
rd voted_2012 prereg days_ratio_flipped if voter_is_male==1 , covar(voter_is_democrat voter_is_minorparty voter_is_unaffiliated    voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace  hs_degree poverty turnout age white black obamaofficeincounty0or1) r


*************************************** FL MECHANISMS **********************************************************************

******************************************** TABLE A9 *********************************

use "C:\projects\Data\Preregistration Paper\Analysis\Pre-Reg FL Data 8.6.13.dta", clear
rename _merge _merge_controls
merge m:1 county_codes_cluster using "C:\projects\Data\Preregistration Paper\Analysis\school performance.dta"

*Voting systems demonstrations in high schools (mentioned in the paper, table in the appendix)
 ivtreatreg voted_2012 prereg, iv(non_eligible_2008 days_ratio_flipped  days_ratio_flipped_2 days_ratio_flipped_3 days_ratio_flipped_4  ) model(direct-2sls) hetero(voting_systems_12)
	test prereg+ _ws_voting_systems_12 = prereg // p values
 ivtreatreg voted_2012 prereg, iv(non_eligible_2008 days_ratio_flipped  days_ratio_flipped_2 days_ratio_flipped_3 days_ratio_flipped_4 voter_is_black voter_is_hispanic voter_is_raceunknown voter_is_minorrace voter_is_democrat voter_is_minorparty voter_is_unaffiliated voter_is_female voter_is_unknowngender  hs_degree poverty turnout age white black obamaofficeincounty0or1  ) model(direct-2sls) hetero(voting_systems_12)
	test prereg+ _ws_voting_systems_12 = prereg // p values
 
******************************************** FIGURE A2 *********************************

use  "C:\projects\Data\Preregistration Paper\Analysis\2004 and 2008.dta", clear
keep voter_id days_ratio_flipped voted
sort voter_id
quietly by voter_id:  gen dup = cond(_N==1,0,_n)
sum dup
tab dup
drop if dup>1
drop dup
save "C:\projects\Data\Preregistration Paper\Analysis\2004 and 2008 proximity.dta", replace

use "C:\projects\Data\Preregistration Paper\Analysis\91-94 extension condensed.dta", clear
append using "C:\projects\Data\Preregistration Paper\Analysis\Pre-Reg FL Data 8.6.13 condensed.dta"
append using "C:\projects\Data\Preregistration Paper\Analysis\87-90 fl registers 2.dta"

replace n_election_date_2008=17840

gen election_birth_2004="11/2/1986"
gen double n_election_date_2004_birth = date(election_birth_2004, "MDY", 2013)
sum n_election_date_2004_birth

gen eligible_2004=1 if birth_date>9620 & birth_date<=9802
replace eligible_2004=0 if eligible_2004==.

replace eligible_prereg_during_08=1 if eligible_prereg_during_08==.
replace eligible_2008=0 if extension==1 & eligible_prereg_during_08==1

*twoway (scatter pre_reg birth_date) (lpoly pre_reg birth_date if eligible_2008==1) (lpoly pre_reg birth_date if eligible_2008==0) (lpoly pre_reg birth_date if extension==1 & eligible_prereg_during_08==1) (lpoly pre_reg birth_date if extension==1 & eligible_prereg_during_08==0)
*twoway (lpoly pre_reg birth_date if eligible_2008==1, ylabel(0.0(0.2)1)bw(100) xline(11265, lpattern(dot) lcolor(red)) xline(11631, lpattern(dot) lcolor(red)) xline(11997, lpattern(dot) lcolor(red))) (lpoly pre_reg birth_date if eligible_2008==0, bw(100)) (lpoly pre_reg birth_date if extension==1 & eligible_prereg_during_08==0, bw(100))

replace eligible_2008=0 if eligible_2008==.

gen election_birth_2008="11/4/1990"
gen double n_election_date_2008_birth = date(election_birth_2008, "MDY", 2013)
sum n_election_date_2008_birth

*twoway (lpoly pre_reg birth_date if birth_date>9620 & birth_date<=9802, lcolor(black) xlabel(9802 "11/2/1986" 10167 "11/2/1987" 10533 "11/2/1988" 10899 "11/2/1989" 11265 "11/4/1990" 11631 "11/4/1991" 11997 "11/4/1992" 12363 "11/4/1993") ylabel(0(0.2)1) bw(100) xline(9802, lpattern(dot) lcolor(red)) xline(10167, lpattern(dot) lcolor(red)) xline(10533, lpattern(dot) lcolor(red)) xline(10899, lpattern(dot) lcolor(red)) xline(11265, lpattern(dot) lcolor(red)) xline(11631, lpattern(dot) lcolor(red)) xline(11997, lpattern(dot) lcolor(red)) xline(12363, lpattern(dot) lcolor(red))) (lpoly pre_reg birth_date if birth_date>9802 & birth_date<=11265 , bw(100) lcolor(black)) (lpoly pre_reg birth_date if  birth_date>11265 , bw(100) lcolor(black))

*How many preregistrations happened during the campaign vs. not?

*For those in the voter file, born May 2, 1986 through May 4, 1994...
*Came of age in 2004, 2005, 2006, 2007, 2008, 2009, 2010, and 2011. 
*birth_date and register_date are benchmarked from January 1, 1960
*May 2, 1986= 9620 in birth_date variable
*May 4, 1994= 12542 in birth_date variable

gen birthday=birth_date
format birthday %d // tells the calendar day
gen registration_day=register_date
format registration_day %d
gen register_year=year(registration_day)
gen register_month=month(registration_day)
replace register_year=. if register_year<2002 // 48 miscodes
tab register_year if pre_reg==1 // this should give us our answer ****
gen register_election_year=1 if register_year==2002 | register_year==2004 | register_year==2006 | register_year==2008 ///
	| register_year==2010 | register_year==2012
replace register_election_year=0 if register_year==2003 | register_year==2005 | register_year==2007 | register_year==2009 ///
	| register_year==2011 
tab register_election_year if pre_reg==1 // THIS IS WHERE WE GET THE STATISTIC 62.4%.

gen register_year_before_2008=1 if register_year==2007 & register_month>=11
replace register_year_before_2008=1 if register_year==2008 & register_month<11
replace register_year_before_2008=0 if register_year==2008 & register_month>=11
replace register_year_before_2008=0 if register_year==2009 & register_month<11



******** 
*gen register_day_no_year=doy(registration_day)
*replace register_day_no_year=. if register_year==.

*egen number_preregistrations=sum(pre_reg), by(register_day_no_year)
*gen register_day_no_year1=register_day_no_year

*collapse (firstnm) number_preregistrations register_day_no_year, by(register_day_no_year1)

*replace register_day_no_year=register_day_no_year-1
*gen register_day_no_year2=register_day_no_year
*format register_day_no_year2 %d

*cd "C:\Users\jbh39\Dropbox\civic engagement\preregistration\paperdraft"
*twoway (line number_preregistrations register_day_no_year, xlabel(1 "Jan 1" 32 "Feb 1" 60 "Mar 1" 91 "Apr 1"   ///
*	121 "May 1"  152 "Jun 1" 182 "Jul 1" 213 "Aug 1" 244 "Sep 1"  274 "Oct 1"  305 "Nov 1"  335 "Dec 1" ) xtitle("Date") ytitle("Number of Preregistrations"))
*graph save preregcountbydoy.gph


